<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>EventDemo</title>
    <script>
        window.onload=function () {
            document.getElementById("inp").onkeydown=function (event) {
                alert(event.keyCode);
            }
            window.onkeydown=function (e) {
                alert(e.keyCode);
            }
        }
    </script>
</head>
<body>
<input type="text" id="inp">
</body>
</html>